<!DOCTYPE html>
<html>
<head>
<base href="${basePath}">
<meta charset="UTF-8">
<title>角色管理</title> $!{include("import_js_css.html")}
<link rel="stylesheet" type="text/css"
	href="${viewPath}/resources/css/basic.css" />
</head>
<body>
	$!{include("header.html")}
	<div class="container menu_all">
		<div class="tabbable tabs-left" id="div_ul_tab">
			$!{include("basic_tab.html")}
			<div class="tab-content">
				<!-- 查询条件 -->
				<div class="tab-pane active" id="panel-task">
					<form class="form-horizontal" role="form" name="taskForm"
						action="yueyogaAdmin/findRoleUsers.jhtml" method="post">
						<div class="form-group">
							<div class="panel-basic-search">
								<label for="txtUserName" class="col-sm-1 control-label">名称</label>
								<div class="col-sm-3">
									<input type="text" class="form-control" name="userName"
										id="txtUserName" value="${name}">
								</div>
								<label for="txtUserEnabled" class="col-sm-1 control-label">是否启用</label>
								<div class="col-sm-3">
									<select class="selectpicker show-menu-arrow" data-width="100%"
										name="enabled" id="enabled">
										<option value=""> </option>
										<!-- #if(enabled == 1) -->
											<option value="1" selected>启用</option>
										<!-- #else -->
											<option value="1">启用</option>
										<!-- #end -->
										
										<!-- #if(enabled == 0) -->
											<option value="0" selected>禁用</option>
										<!-- #else -->
											<option value="0">禁用</option>
										<!-- #end -->
									</select>
								</div>
								<br /> <br /> <input type="hidden" name="pageNo"
									id="hidPageNo" />
								<div class="panel-btn-basic">
									<button type="submit" class="btn-ade-default2">搜索</button>
								</div>
							</div>
						</div>
					</form>
				</div>
			</div>
		</div>
		<!-- #set(PaginatedList<Role> roles) -->
		<div class="div_search_result">
			<div class="panel-heading panel-result-title">
				<h3 class="panel-title">查询结果</h3>
				<input type="hidden" id="roleId" />
				<div class="btn-group btn-group-sm btn-gp-default">
					<button id="btn_add" type="button"
						class="btn btn-default panel-radius-left">添加</button>
					<button id="btn_edit" type="button"
						class="btn btn-default panel-radius-none">修改</button>
					<button id="btn_delete" type="button"
						class="btn btn-default panel-radius-none">删除</button>
					<button id="btn_zdqx" type="button"
						class="btn btn-default panel-radius-right">指定权限</button>
				</div>
			</div>
			<!-- 查询结果 -->
			<!-- #if(roles) -->
			<table class="table table-bordered table-hover table-condensed tb"
				style="text-align: center; border-bottom: 1px solid #DDDDDD;">
				<tr>
					<td width="100px"><input id="chkallIds" type="checkbox" /></td>
					<td width="200px">名称</td>
					<td width="300px">权限</td>
					<td>描述</td>
					<td width="120px">状态</td>
				<tr>
					<!--#for(Role role : roles)-->
				<tr>
					<td><input name="chk_name" type="checkbox" value="${role.id}" /></td>
					<td>${role.name}</td>
					<td id="td_${role.id}">${role.qxmc}</td>
					<td>${role.description}</td>
					<td>${role.enabled=='true'?'启用':'禁用'}</td>
				</tr>
				<!--#end-->
			</table>
			<!-- 列表分页 -->
			<!--
				#set(
				pager = roles.pager,
				totalResults = pager.getCountOfTotalResults(),
				totalPages = pager.getCountOfTotalPages() * 1,
				pageSize = pager.pageSize,
				pageNo = pager.pageNo,
				prePageNo = pager.getPrevPageNo(),
				nextPageNo = pager.getNextPageNo()
				)
				-->
			<div class="paging-page">$!{include("paging_page.html")}</div>
			<!-- #else -->
			<div class="panel-body">没有符合条件的数据</div>
			<!-- #end -->
		</div>
		<div id="urs_role" class="panel-dialog-box panel-radius-all"
			style="width: 420px; display: none; z-index: 1000; min-height: 140px;">
			<div class="panel-heading panel-result-title">
				<h3 class="panel-title">指定权限</h3>
				<br> <br>
				<label class="col-sm-1 control-label">当前权限</label>
				<label id="lbcurAuthorities" style="width: 275px !important;" class="col-sm-1 control-label"></label> 
				<br> <br> 
				<label for="selResoures" class="col-sm-1 control-label">重赋权限</label>
				<div class="col-sm-8">
					<select class="selectpicker" multiple data-width="100%" name="resources" id="selAuthorities">
						<option value=""></option>
						<!-- #for(Authority au:authorities) -->
						<option value="${au.id},">${au.name}</option>
						<!-- #end -->
					</select>
				</div>
				<br> <br>
				
				<input type="hidden" id="hidAuthorityId" />
				<div class="panel-btn-search" style="float: left; text-align: right; margin-top: 20px; margin-left: 110px;">
					<button id="btnGrantAuthority" type="button" class="btn-adet-default">保存</button>
					&nbsp;&nbsp;&nbsp;
					<button type="button" id="btn_close" onclick="slideToggleDIV()" class="btn-adet-default">取消</button>
				</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript">
	$(function() {
		$("#enabled").select2({
			width: "100%",
			minimumResultsForSearch: -1
		});
		
		var enabled = '${enabled}';
		$("#enabled").select2("val", enabled);
		//删除
		$("#btn_delete").click(
				function btn_delete() {
					var ids = new Array();
					$("input[name='chk_name']:checked").each(function() {
						ids.push($(this).val());
					});
					if (ids.length > 0) {
						confirm('确定要删除吗？', function() {
							var url = "yueyogaAdmin/deleteRole.jhtml?ids="
									+ ids;
							$.post(url, function(resp) {
								var data = eval('(' + resp + ')');
								if (data.success) {
									var d = alert(data.msg);
									setTimeout(function() {
										d.close().remove();
										$("input[name='chk_name']").prop(
												'checked', false);
										$("#selResoures").select2("val", "");
										$('.selectpicker').selectpicker(
												'refresh');
									}, 1000);
									$("form[name='taskForm']").submit();
								} else {
									error(data.msg);
								}
							});
						});
					} else {
						alert("请选择您要删除的记录!");
					}
				});
		//--全选`反选
		$("#chkallIds").click(function() {
			if (this.checked) {
				$("input[name='chk_name']").each(function() {
					this.checked = true;
				});
			} else {
				$("input[name='chk_name']").each(function() {
					this.checked = false;
				});
			}
		});

		$("#btn_add").click(function() {
			window.location.href = "yueyogaAdmin/toAddRoleUser.jhtml";
		});

		$("#btn_edit")
				.click(
						function() {
							var ids = new Array();
							$("input[name='chk_name']:checked").each(
									function() {
										ids.push($(this).val());
									});
							if (ids.length == 1) {
								window.location.href = "yueyogaAdmin/toUpdateRoleUser.jhtml?roleId="
										+ ids;
							} else {
								var d = alert("请选择一条记录进行修改!");
								setTimeout(function() {
									d.close().remove();
									$("input[name='chk_name']").prop('checked',
											false);
								}, 1000);
							}
						});
		$("#btn_zdqx").click(function() {
			var ids = new Array();
			$("input[name='chk_name']:checked").each(function() {
				ids.push($(this).val());
			});

			if (ids.length == 1) {
				$("#selAuthorities").select2("val", "");
				$("#roleId").val(ids);
				//--当前权限
				$("#lbcurAuthorities").text($("#td_" + ids).text());
				slideToggleDIV();
			} else {
				var s = alert("请选择一条记录进行操作!");
				setTimeout(function() {
					s.close().remove();
					$("input[name='chk_name']").prop("checked", false);
				}, 1000);
			}
		});
		//--指定权限
		$("#btnGrantAuthority").click(function() {
			var auIds = $("#selAuthorities").select2("val") + "";
			var roleId = $("#roleId").val();
			if (auIds && roleId && auIds.length > 0) {
				slideToggleDIV();
				auIds = auIds.substring(0, auIds.length - 1);
				var url = "yueyogaAdmin/grantRoleAuthorities.jhtml";
				$.post(url, {
					auIds : auIds,
					roleId : roleId
				}, function(resp) {
					var data = eval('(' + resp + ')');
					if (data.success) {
						var d = alert(data.msg);
						setTimeout(function() {
							d.close().remove();
							$("input[name=chk_name]").prop("checked", false);
						}, 1000);
						$("form[name='taskForm']").submit();
					} else {
						error(data.msg);
					}
					$("#selAuthorities").select2("val", "");
				});
			}
		});

	});
	function slideToggleDIV() {
		$("#urs_role").slideToggle(0);
	}

	function changePage(value) {
		value = value * 1;
		var totalPages = '${totalPages}';
		if (value > totalPages) {
			value = totalPages;
		} else if (value < 1) {
			value = 1;
		}
		$("#txtPageNumber").val(value);
		goToPage(value);
	}
	function goToPage(pageNo) {
		$("#hidPageNo").val(pageNo);
		document.taskForm.submit();
	}
</script>
</html>